#include <stdio.h>
#include <string.h>
#include <errno.h>

#define TEST_FILE_NAME "19_Test.txt"

#if 0
int isUnkownError(int iError)
{
    int iRet;
    errno = iError;
    char strErrBuff[50]={0};
    strcpy(strErrBuff, strerror(errno));
    iRet = strncmp(strErrBuff, "Unknown error", sizeof("Unknown error"-1));    
    return iRet;

// can't work, because when errno=41, the strerror is "Unknown error 41"
}
#endif

int main(int argc, char const *argv[])
{
    FILE *fp = fopen( TEST_FILE_NAME, "w" );
    if( NULL == fp)
    {
        perror("Fail to open file\n");
        return -1;
    }

    int i;
    for(i=0; i<140; ++i)
    {
        errno = i;   
        fprintf( fp, "errno %3d : %s\n", errno, strerror(errno) );
        printf( "errno %3d : %s\n", errno, strerror(errno) );
    }

#if 0
    i = 39;
    while( isUnkownError(i) )
    {
        errno = i;   
        fprintf(fp, "errno %3d : %s\n", errno, strerror(errno));
        ++i;            
    }
 #endif
    

    fclose(fp);

    printf("---End of 19_errno.c---\n");  
    
    return 0;
}
